import {Component} from 'react';
import { Swiper } from 'react-vant';
import { getLikeList } from '../../../api/info';
import './index.less'
import Lazyimg from 'react-lazyimg-component';
import loadingImg from '../../../assets/loading.png'
class Like extends Component{
    state={
        likeList:[]
    }
    render(){
        let {likeList} = this.state;
        return(
            <div>
                {
                    likeList.length!=0 && <Swiper autoplay={5000}>
                        {
                            likeList.map((item,index)=>{
                               return (
                                <Swiper.Item key={index}>
                                <div className='likeList'>
                                {
                                    item.map((like,i)=>{
                                        return (
                                            <div key={i} className='like_item'>
                                                 <Lazyimg className="like_img" src={like.image} placeholder={<img src={loadingImg} alt='加载失败'/>}/>
                                                <p className='like_name'>{like.storeName}</p>
                                                <p className='like_price'>￥{like.price}</p>
                                            </div>
                                        )
                                    })
                                }
                                </div>
                            </Swiper.Item>
                               )
                            })
                        }
                    </Swiper>
                }
            </div>
        )
    }
    async componentDidMount(){
       let res = await getLikeList();
       let list = res.data.data.list;
        // 总数据量
       let sum =list.length;
        //总共几个元素
       let num = Math.ceil( sum / 6);
       let arry = [];
       for(let i=0;i<num;i++){
         arry[i] = list.splice(0,6)
       }
       console.log(arry)
       this.setState({
        likeList:arry 
       })
    }
}
export default Like;